package com.ly.web.controller.erp;

import java.util.List;

import com.ly.common.utils.StringUtils;
import com.ly.heart.domain.dto.ContractOrderMaterialDetailDto;
import com.ly.heart.domain.dto.ContractProcureOrderDto;
import com.ly.heart.domain.vo.ContractOrderMaterialDetailVo;
import com.ly.heart.service.IContractProcureService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ly.common.annotation.Log;
import com.ly.common.core.controller.BaseController;
import com.ly.common.core.domain.AjaxResult;
import com.ly.common.enums.BusinessType;
import com.ly.heart.domain.ContractProcureEntity;
import com.ly.common.core.page.TableDataInfo;

import javax.annotation.Resource;

/**
 * 采购合同;1:采购;2:行政;Controller
 * @author wutao
 * @date 2024-05-31
 */
@Api (value = "ContractProcure", tags = "采购合同;1:采购;2:行政;")
@RestController
@RequestMapping ("/heart/ContractProcure")
public class ContractProcureController extends BaseController {

    @Resource
    private IContractProcureService contractProcureEntityService;

    /**
     * 查询采购合同;1:采购;2:行政;列表
     */
    @PreAuthorize ("@ss.hasPermi('heart:ContractProcure:list')")
    @GetMapping ("/list")
    @ApiOperation ("查询采购合同;1:采购;2:行政;列表")
    @Log (title = "采购合同列表")
    public AjaxResult list (ContractProcureEntity contractProcureEntity) {
        AjaxResult ajaxResult = contractProcureEntityService.selectContractProcureEntityList ( contractProcureEntity );
        return ajaxResult;
    }

    /**
     * 获取采购合同;1:采购;2:行政;详细信息
     */
    @PreAuthorize ("@ss.hasPermi('heart:ContractProcure:query')")
    @GetMapping (value = "/{id}")
    @ApiOperation ("获取采购合同;1:采购;2:行政;详细信息")
    public AjaxResult getInfo (@PathVariable ("id") String id) {
        return AjaxResult.success ( contractProcureEntityService.selectContractProcureEntityById ( id ) );
    }

    /**
     * 暂存;
     */
    @PreAuthorize ("@ss.hasPermi('heart:ContractProcure:add')")
    @Log (title = "暂存采购合同;1:采购;2:行政;", businessType = BusinessType.INSERT)
    @PostMapping ("draft")
    @ApiOperation ("暂存采购合同;1:采购;2:行政;")
    public AjaxResult draft (@RequestBody ContractProcureOrderDto contractProcureOrderDto) {
        ContractProcureEntity contractProcureEntity = contractProcureOrderDto.getContractProcureEntity ();
        if ( StringUtils.isNotBlank ( contractProcureEntity.getId () ) ) {
            return contractProcureEntityService.updateContractProcureEntity ( contractProcureOrderDto );
        }
        return contractProcureEntityService.draft ( contractProcureOrderDto );
    }

    /**
     * 新增采购合同;1:采购;2:行政;
     */
    @PreAuthorize ("@ss.hasPermi('heart:ContractProcure:add')")
    @Log (title = "提交采购合同;1:采购;2:行政;", businessType = BusinessType.INSERT)
    @PostMapping ("submit")
    @ApiOperation ("提交采购合同;1:采购;2:行政;")
    public AjaxResult submit (@RequestBody ContractProcureEntity contractProcureEntity) {
        return contractProcureEntityService.submit ( contractProcureEntity );
    }

    /**
     * 修改采购合同;1:采购;2:行政;
     */
    @PreAuthorize ("@ss.hasPermi('heart:ContractProcure:edit')")
    @Log (title = "采购合同;1:采购;2:行政;", businessType = BusinessType.UPDATE)
    @PutMapping
    @ApiOperation ("修改采购合同;1:采购;2:行政;")
    public AjaxResult edit (@RequestBody ContractProcureOrderDto contractProcureOrderDto) {
        return contractProcureEntityService.updateContractProcureEntity ( contractProcureOrderDto );
    }

    /**
     * 删除采购合同;1:采购;2:行政;
     */
    @PreAuthorize ("@ss.hasPermi('heart:ContractProcure:remove')")
    @Log (title = "采购合同;1:采购;2:行政;", businessType = BusinessType.DELETE)
    @DeleteMapping ("/{ids}")
    @ApiOperation ("删除采购合同;1:采购;2:行政;")
    public AjaxResult remove (@PathVariable String[] ids) {
        return contractProcureEntityService.deleteContractProcureEntityByIds ( ids );
    }

    @PreAuthorize ("@ss.hasPermi('heart:ContractProcure:close')")
    @RequestMapping ("close")
    @Log (title = "采购合同，整单关闭;")
    @ApiOperation ("采购合同，整单关闭")
    public AjaxResult close (String id) {
        return contractProcureEntityService.close ( id );
    }

    @PreAuthorize ("@ss.hasPermi('heart:ContractProcure:cancel')")
    @RequestMapping ("cancel")
    @Log (title = "采购合同，作废;")
    @ApiOperation ("采购合同，作废")
    public AjaxResult cancel (String id) {
        return contractProcureEntityService.cancel ( id );
    }

    /**
     * 根据采购合同对象List查询物料明细
     */
    @Log (title = "根据采购合同对象List查询物料明细")
    @GetMapping ("queryMaterial")
    @ApiOperation ("根据采购合同对象List查询物料明细")
    public AjaxResult queryMaterial (ContractOrderMaterialDetailDto contractOrderMaterialDetailDto) {

        return contractProcureEntityService.queryMaterial ( contractOrderMaterialDetailDto );
    }


}
